package com.canaan.business.controller.pc.print;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.print.PrintRecord;
import com.canaan.business.service.print.IPrintRecordService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 打印记录Controller
 *
 * @author canaan
 * @date 2025-04-20
 */
@Api(tags = "打印记录")
@RestController
@RequestMapping("/print/record")
public class PrintRecordController extends BaseController {
    @Resource
    private IPrintRecordService printRecordService;

    /**
     * 查询打印记录列表
     */
    @ApiOperation(value = "查询打印记录列表")
//    @PreAuthorize("@ss.hasPermi('print:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrintRecord printRecord) {
        startPage();
        List<PrintRecord> list = printRecordService.selectPrintRecordList(printRecord);
        return getDataTable(list);
    }

    /**
     * 导出打印记录列表
     */
    @ApiOperation(value = "导出打印记录列表")
//    @PreAuthorize("@ss.hasPermi('print:record:export')")
    @Log(title = "打印记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrintRecord printRecord) {
        List<PrintRecord> list = printRecordService.selectPrintRecordList(printRecord);
        ExcelUtil<PrintRecord> util = new ExcelUtil<PrintRecord>(PrintRecord.class);
        util.exportExcel(response, list, "打印记录数据");
    }

    /**
     * 获取打印记录详细信息
     */
    @ApiOperation(value = "获取打印记录详细信息")
//    @PreAuthorize("@ss.hasPermi('print:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(printRecordService.selectPrintRecordById(id));
    }

    /**
     * 新增打印记录
     */
    @ApiOperation(value = "新增打印记录")
//    @PreAuthorize("@ss.hasPermi('print:record:add')")
    @Log(title = "打印记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrintRecord printRecord) {
        return toAjax(printRecordService.insertPrintRecord(printRecord));
    }

    /**
     * 修改打印记录
     */
    @ApiOperation(value = "修改打印记录")
//    @PreAuthorize("@ss.hasPermi('print:record:edit')")
    @Log(title = "打印记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrintRecord printRecord) {
        return toAjax(printRecordService.updatePrintRecord(printRecord));
    }

    /**
     * 删除打印记录
     */
    @ApiOperation(value = "删除打印记录")
//    @PreAuthorize("@ss.hasPermi('print:record:remove')")
    @Log(title = "打印记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(printRecordService.deletePrintRecordByIds(ids));
    }

    /**
     * 查询最新打印记录
     */
    @ApiOperation(value = "查询最新打印记录")
//    @PreAuthorize("@ss.hasPermi('print:record:export')")
    @Log(title = "查询最新打印记录", businessType = BusinessType.OTHER)
    @GetMapping("/getPrintRecord")
    public AjaxResult getPrintRecord(@RequestParam("trayNo") String trayNo) {
        return printRecordService.getPrintRecord(trayNo);
    }
}
